<!DOCTYPE html>
<html>

<head>
  <title>Quarkus - Testing Your Application</title>
  <script id="adobe_dtm" src="https://www.redhat.com/dtm.js" type="text/javascript"></script>
  <script src="/assets/javascript/highlight.pack.js" type="text/javascript"></script>
  <META HTTP-EQUIV='Content-Security-Policy' CONTENT="default-src 'none'; script-src 'self' 'unsafe-eval' 'sha256-ANpuoVzuSex6VhqpYgsG25OHWVA1I+F6aGU04LoI+5s=' 'sha256-ipy9P/3rZZW06mTLAR0EnXvxSNcnfSDPLDuh3kzbB1w=' js.bizographics.com https://www.redhat.com assets.adobedtm.com jsonip.com https://ajax.googleapis.com https://www.googletagmanager.com https://www.google-analytics.com https://use.fontawesome.com; style-src 'self' https://fonts.googleapis.com https://use.fontawesome.com; img-src 'self' *; media-src 'self' ; frame-src https://www.googletagmanager.com https://www.youtube.com; frame-ancestors 'none'; base-uri 'none'; object-src 'none'; form-action 'none'; font-src 'self' https://use.fontawesome.com https://fonts.gstatic.com;">
  <META HTTP-EQUIV='X-Frame-Options' CONTENT="DENY">
  <META HTTP-EQUIV='X-XSS-Protection' CONTENT="1; mode=block">
  <META HTTP-EQUIV='X-Content-Type-Options' CONTENT="nosniff">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="description" content="Quarkus: Supersonic Subatomic Java">
  <meta name="twitter:card" content="summary_large_image">
  <meta name="twitter:site" content="@QuarkusIO"> 
  <meta name="twitter:creator" content="@QuarkusIO">
  <meta property="og:url" content="https://quarkus.io/guides/getting-started-testing" />
  <meta property="og:title" content="Quarkus - Testing Your Application" />
  <meta property="og:description" content="Quarkus: Supersonic Subatomic Java" />
  <meta property="og:image" content="/assets/images/quarkus_card.png" />
  <link rel="canonical" href="https://quarkus.io/guides/getting-started-testing">
  <link rel="shortcut icon" type="image/png" href="/favicon.ico" >
  <link rel="stylesheet" href="https://quarkus.io/guides/stylesheet/config.css" />
  <link rel="stylesheet" href="/assets/css/main.css" />
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.1.0/css/all.css" integrity="sha384-lKuwvrZot6UHsBSfcMvOkWwlCMgc0TaWr+30HWe3a4ltaBwTZhyTEggF5tJv8tbt" crossorigin="anonymous">
  <link rel="alternate" type="application/rss+xml"  href="https://quarkus.io/feed.xml" title="Quarkus">
  <script src="https://quarkus.io/assets/javascript/goan.js" type="text/javascript"></script>
  <script src="https://quarkus.io/assets/javascript/hl.js" type="text/javascript"></script>
</head>

<body class="guides">
  <!-- Google Tag Manager (noscript) -->
  <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-NJWS5L"
  height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
  <!-- End Google Tag Manager (noscript) -->

  <div class="nav-wrapper">
  <div class="grid-wrapper">
    <div class="width-12-12">
      <input type="checkbox" id="checkbox" />
      <nav id="main-nav" class="main-nav">
  <div class="container">
    <div class="logo-wrapper">
      
        <a href="/"><img src="/assets/images/quarkus_logo_horizontal_rgb_600px_reverse.png" class="project-logo" title="Quarkus"></a>
      
    </div>
    <label class="nav-toggle" for="checkbox">
      <i class="fa fa-bars"></i>
    </label>
    <div id="menu" class="menu">
      <span>
        <a href="/get-started/" class="">Get Started</a>
      </span>
      <span>
        <a href="/guides/" class="active">Guides</a>
      </span>
      <span>
        <a href="/community/" class="">Community</a>
      </span>
      <span>
        <a href="/support/" class="">Support</a>
      </span>
      <span>
        <a href="/blog/" class="">Blog</a>
      </span>
      <span>
        <a href="https://code.quarkus.io" class="button-cta secondary white">Start Coding</a>
      </span>
    </div>
  </div>
      </nav>
    </div>
  </div>
</div>

  <div class="content">
    <div class="guide">
  <div class="width-12-12">
    <h1 class="text-caps">Quarkus - Testing Your Application</h1>
    <div class="hide-mobile toc"><ul class="sectlevel1">
<li><a href="#prerequisites">1. Prerequisites</a></li>
<li><a href="#architecture">2. Architecture</a></li>
<li><a href="#solution">3. Solution</a></li>
<li><a href="#recap-of-http-based-testing-in-jvm-mode">4. Recap of HTTP based Testing in JVM mode</a>
<ul class="sectlevel2">
<li><a href="#controlling-the-test-port">4.1. Controlling the test port</a></li>
<li><a href="#injecting-a-uri">4.2. Injecting a URI</a></li>
</ul>
</li>
<li><a href="#testing-a-specific-endpoint">5. Testing a specific endpoint</a>
<ul class="sectlevel2">
<li><a href="#testhttpresource">5.1. TestHTTPResource</a></li>
<li><a href="#restassured">5.2. RESTassured</a></li>
</ul>
</li>
<li><a href="#injection-into-tests">6. Injection into tests</a></li>
<li><a href="#applying-interceptors-to-tests">7. Applying Interceptors to Tests</a></li>
<li><a href="#enrichment-via-quarkustestcallback">8. Enrichment via QuarkusTest*Callback</a></li>
<li><a href="#testing_different_profiles">9. Testing Different Profiles</a>
<ul class="sectlevel2">
<li><a href="#writing-a-profile">9.1. Writing a Profile</a></li>
</ul>
</li>
<li><a href="#mock-support">10. Mock Support</a>
<ul class="sectlevel2">
<li><a href="#cdi-alternative-mechanism">10.1. CDI <code>@Alternative</code> mechanism.</a></li>
<li><a href="#mocking-using-quarkusmock">10.2. Mocking using QuarkusMock</a></li>
<li><a href="#mocking-with-panache">10.3. Mocking with Panache</a></li>
</ul>
</li>
<li><a href="#testing-security">11. Testing Security</a></li>
<li><a href="#quarkus-test-resource">12. Starting services before the Quarkus application starts</a></li>
<li><a href="#native-executable-testing">13. Native Executable Testing</a></li>
<li><a href="#test-from-ide">14. Running <code>@QuarkusTest</code> from an IDE</a>
<ul class="sectlevel2">
<li><a href="#eclipse-separate-jre-definition">14.1. Eclipse separate JRE definition</a></li>
<li><a href="#vscode-run-with-configuration">14.2. VSCode "run with" configuration</a></li>
<li><a href="#intellij-junit-template">14.3. IntelliJ JUnit template</a></li>
</ul>
</li>
</ul></div>
    <div>
      <div id="preamble">
<div class="sectionbody">
<div class="paragraph">
<p>Learn how to test your Quarkus Application.
This guide covers:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Testing in JVM mode</p>
</li>
<li>
<p>Testing in native mode</p>
</li>
<li>
<p>Injection of resources into tests</p>
</li>
</ul>
</div>
</div>
</div>
<div class="sect1">
<h2 id="prerequisites"><a class="anchor" href="#prerequisites"></a>1. Prerequisites</h2>
<div class="sectionbody">
<div class="paragraph">
<p>To complete this guide, you need:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>less than 15 minutes</p>
</li>
<li>
<p>an IDE</p>
</li>
<li>
<p>JDK 1.8+ installed with <code>JAVA_HOME</code> configured appropriately</p>
</li>
<li>
<p>Apache Maven 3.6.2+</p>
</li>
<li>
<p>The completed greeter application from the <a href="getting-started">Getting Started Guide</a></p>
</li>
</ul>
</div>
</div>
</div>
<div class="sect1">
<h2 id="architecture"><a class="anchor" href="#architecture"></a>2. Architecture</h2>
<div class="sectionbody">
<div class="paragraph">
<p>In this guide, we expand on the initial test that was created as part of the Getting Started Guide.
We cover injection into tests and also how to test native executables.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="solution"><a class="anchor" href="#solution"></a>3. Solution</h2>
<div class="sectionbody">
<div class="paragraph">
<p>We recommend that you follow the instructions in the next sections and create the application step by step.
However, you can go right to the completed example.</p>
</div>
<div class="paragraph">
<p>Clone the Git repository: <code>git clone <a href="https://github.com/quarkusio/quarkus-quickstarts.git" class="bare">https://github.com/quarkusio/quarkus-quickstarts.git</a></code>, or download an <a href="https://github.com/quarkusio/quarkus-quickstarts/archive/master.zip">archive</a>.</p>
</div>
<div class="paragraph">
<p>The solution is located in the <code>getting-started-testing</code> directory.</p>
</div>
<div class="paragraph">
<p>This guide assumes you already have the completed application from the <code>getting-started</code> directory.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="recap-of-http-based-testing-in-jvm-mode"><a class="anchor" href="#recap-of-http-based-testing-in-jvm-mode"></a>4. Recap of HTTP based Testing in JVM mode</h2>
<div class="sectionbody">
<div class="paragraph">
<p>If you have started from the Getting Started example you should already have a completed test, including the correct
<code>pom.xml</code> setup.</p>
</div>
<div class="paragraph">
<p>In the <code>pom.xml</code> file you should see 2 test dependencies:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="xml" class="language-xml hljs">&lt;dependency&gt;
    &lt;groupId&gt;io.quarkus&lt;/groupId&gt;
    &lt;artifactId&gt;quarkus-junit5&lt;/artifactId&gt;
    &lt;scope&gt;test&lt;/scope&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;io.rest-assured&lt;/groupId&gt;
    &lt;artifactId&gt;rest-assured&lt;/artifactId&gt;
    &lt;scope&gt;test&lt;/scope&gt;
&lt;/dependency&gt;</code></pre>
</div>
</div>
<div class="paragraph">
<p><code>quarkus-junit5</code> is required for testing, as it provides the <code>@QuarkusTest</code> annotation that controls the testing framework.
<code>rest-assured</code> is not required but is a convenient way to test HTTP endpoints, we also provide integration that automatically
sets the correct URL so no configuration is required.</p>
</div>
<div class="paragraph">
<p>Because we are using JUnit 5, the version of the <a href="https://maven.apache.org/surefire/maven-surefire-plugin/">Surefire Maven Plugin</a>
must be set, as the default version does not support Junit 5:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="xml" class="language-xml hljs">&lt;plugin&gt;
    &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
    &lt;version&gt;${surefire-plugin.version}&lt;/version&gt;
    &lt;configuration&gt;
       &lt;systemPropertyVariables&gt;
          &lt;java.util.logging.manager&gt;org.jboss.logmanager.LogManager&lt;/java.util.logging.manager&gt;
          &lt;maven.home&gt;${maven.home}&lt;/maven.home&gt;
       &lt;/systemPropertyVariables&gt;
    &lt;/configuration&gt;
&lt;/plugin&gt;</code></pre>
</div>
</div>
<div class="paragraph">
<p>We also set the <code>java.util.logging.manager</code> system property to make sure tests will use the correct logmanager and <code>maven.home</code> to ensure that custom configuration
from <code>${maven.home}/conf/settings.xml</code> is applied (if any).</p>
</div>
<div class="paragraph">
<p>The project should also contain a simple test:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">package org.acme.getting.started.testing;

import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;

import java.util.UUID;

import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.is;

@QuarkusTest
public class GreetingResourceTest {

    @Test
    public void testHelloEndpoint() {
        given()
          .when().get("/hello")
          .then()
             .statusCode(200)
             .body(is("hello"));
    }

    @Test
    public void testGreetingEndpoint() {
        String uuid = UUID.randomUUID().toString();
        given()
          .pathParam("name", uuid)
          .when().get("/hello/greeting/{name}")
          .then()
            .statusCode(200)
            .body(is("hello " + uuid));
    }

}</code></pre>
</div>
</div>
<div class="paragraph">
<p>This test uses HTTP to directly test our REST endpoint. When the test is run the application will be started before
the test is run.</p>
</div>
<div class="sect2">
<h3 id="controlling-the-test-port"><a class="anchor" href="#controlling-the-test-port"></a>4.1. Controlling the test port</h3>
<div class="paragraph">
<p>While Quarkus will listen on port <code>8080</code> by default, when running tests it defaults to <code>8081</code>. This allows you to run
tests while having the application running in parallel.</p>
</div>
<div class="admonitionblock tip">
<table>
<tr>
<td class="icon">
<i class="fa icon-tip" title="Tip"></i>
</td>
<td class="content">
<div class="title">Changing the test port</div>
<div class="paragraph">
<p>You can configure the ports used by tests by configuring <code>quarkus.http.test-port</code> for HTTP and <code>quarkus.http.test-ssl-port</code> for HTTPS in your <code>application.properties</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">quarkus.http.test-port=8083
quarkus.http.test-ssl-port=8446</code></pre>
</div>
</div>
<div class="paragraph">
<p><code>0</code> will result in the use of a random port (assigned by the operating system).</p>
</div>
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>Quarkus also provides RestAssured integration that updates the default port used by RestAssured before the tests are run,
so no additional configuration should be required.</p>
</div>
</div>
<div class="sect2">
<h3 id="injecting-a-uri"><a class="anchor" href="#injecting-a-uri"></a>4.2. Injecting a URI</h3>
<div class="paragraph">
<p>It is also possible to directly inject the URL into the test which can make is easy to use a different client. This is
done via the <code>@TestHTTPResource</code> annotation.</p>
</div>
<div class="paragraph">
<p>Let&#8217;s write a simple test that shows this off to load some static resources. First create a simple HTML file in
<code>src/main/resources/META-INF/resources/index.html</code> :</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="xml" class="language-xml hljs">&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;Testing Guide&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
        Information about testing
    &lt;/body&gt;
&lt;/html&gt;</code></pre>
</div>
</div>
<div class="paragraph">
<p>We will create a simple test to ensure that this is being served correctly:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">package org.acme.getting.started.testing;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.charset.StandardCharsets;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import io.quarkus.test.common.http.TestHTTPResource;
import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
public class StaticContentTest {

    @TestHTTPResource("index.html") <i class="conum" data-value="1"></i><b>(1)</b>
    URL url;

    @Test
    public void testIndexHtml() throws Exception {
        try (InputStream in = url.openStream()) {
            String contents = readStream(in);
            Assertions.assertTrue(contents.contains("&lt;title&gt;Testing Guide&lt;/title&gt;"));
        }
    }

    private static String readStream(InputStream in) throws IOException {
        byte[] data = new byte[1024];
        int r;
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        while ((r = in.read(data)) &gt; 0) {
            out.write(data, 0, r);
        }
        return new String(out.toByteArray(), StandardCharsets.UTF_8);
    }
}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>This annotation allows you to directly inject the URL of the Quarkus instance, the value of the annotation will be the path component of the URL</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>For now <code>@TestHTTPResource</code> allows you to inject <code>URI</code>, <code>URL</code> and <code>String</code> representations of the URL.</p>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="testing-a-specific-endpoint"><a class="anchor" href="#testing-a-specific-endpoint"></a>5. Testing a specific endpoint</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Both RESTassured and <code>@TestHTTPResource</code> allow you to specify the endpoint class you are testing rather than hard coding
a path. This currently supports both JAX-RS endpoints, Servlets and Reactive Routes. This makes it a lot easier to see exactly which endpoints
a given test is testing.</p>
</div>
<div class="paragraph">
<p>For the purposes of these examples I am going to assume we have an endpoint that looks like the following:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@Path("/hello")
public class GreetingResource {

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String hello() {
        return "hello";
    }
}</code></pre>
</div>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
This currently does not support the <code>@ApplicationPath()</code> annotation to set the JAX-RS context path. Use the
<code>quarkus.resteasy.path</code> config value instead if you want a custom context path.
</td>
</tr>
</table>
</div>
<div class="sect2">
<h3 id="testhttpresource"><a class="anchor" href="#testhttpresource"></a>5.1. TestHTTPResource</h3>
<div class="paragraph">
<p>You can the use the <code>io.quarkus.test.common.http.TestHTTPEndpoint</code> annotation to specify the endpoint path, and the path
will be extracted from the provided endpoint. If you also specify a value for the <code>TestHTTPResource</code> endpoint it will
be appended to the end of the endpoint path.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">package org.acme.getting.started.testing;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.charset.StandardCharsets;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import io.quarkus.test.common.http.TestHTTPEndpoint;
import io.quarkus.test.common.http.TestHTTPResource;
import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
public class StaticContentTest {

    @TestHTTPEndpoint(GreetingResource.class)  <i class="conum" data-value="1"></i><b>(1)</b>
    @TestHTTPResource
    URL url;

    @Test
    public void testIndexHtml() throws Exception {
        try (InputStream in = url.openStream()) {
            String contents = readStream(in);
            Assertions.assertTrue(contents.equals("hello"));
        }
    }

    private static String readStream(InputStream in) throws IOException {
        byte[] data = new byte[1024];
        int r;
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        while ((r = in.read(data)) &gt; 0) {
            out.write(data, 0, r);
        }
        return new String(out.toByteArray(), StandardCharsets.UTF_8);
    }
}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>Because <code>GreetingResource</code> is annotated with <code>@Path("/hello")</code> the injected URL
will end with <code>/hello</code>.</td>
</tr>
</table>
</div>
</div>
<div class="sect2">
<h3 id="restassured"><a class="anchor" href="#restassured"></a>5.2. RESTassured</h3>
<div class="paragraph">
<p>To control the RESTassured base path (i.e. the default path that serves as the root for every
request) you can use the <code>io.quarkus.test.common.http.TestHTTPEndpoint</code> annotation. This can
be applied at the class or method level. To test out greeting resource we would do:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">package org.acme.getting.started.testing;

import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.common.http.TestHTTPEndpoint;
import org.junit.jupiter.api.Test;

import java.util.UUID;

import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.is;

@QuarkusTest
@TestHTTPEndpoint(GreetingResource.class) <i class="conum" data-value="1"></i><b>(1)</b>
public class GreetingResourceTest {

    @Test
    public void testHelloEndpoint() {
        given()
          .when().get()    <i class="conum" data-value="2"></i><b>(2)</b>
          .then()
             .statusCode(200)
             .body(is("hello"));
    }
}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>This tells RESTAssured to prefix all requests with <code>/hello</code>.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>Note we don&#8217;t need to specify a path here, as <code>/hello</code> is the default for this test</td>
</tr>
</table>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="injection-into-tests"><a class="anchor" href="#injection-into-tests"></a>6. Injection into tests</h2>
<div class="sectionbody">
<div class="paragraph">
<p>So far we have only covered integration style tests that test the app via HTTP endpoints, but what if we want to do unit
testing and test our beans directly?</p>
</div>
<div class="paragraph">
<p>Quarkus supports this by allowing you to inject CDI beans into your tests via the <code>@Inject</code> annotation (in fact, tests in
Quarkus are full CDI beans, so you can use all CDI functionality). Let&#8217;s create a simple test that tests the greeting
service directly without using HTTP:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">package org.acme.getting.started.testing;

import javax.inject.Inject;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
public class GreetingServiceTest {

    @Inject <i class="conum" data-value="1"></i><b>(1)</b>
    GreetingService service;

    @Test
    public void testGreetingService() {
        Assertions.assertEquals("hello Quarkus", service.greeting("Quarkus"));
    }
}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>The <code>GreetingService</code> bean will be injected into the test</td>
</tr>
</table>
</div>
</div>
</div>
<div class="sect1">
<h2 id="applying-interceptors-to-tests"><a class="anchor" href="#applying-interceptors-to-tests"></a>7. Applying Interceptors to Tests</h2>
<div class="sectionbody">
<div class="paragraph">
<p>As mentioned above Quarkus tests are actually full CDI beans, and as such you can apply CDI interceptors as you would
normally. As an example, if you want a test method to run within the context of a transaction you can simply apply the
<code>@Transactional</code> annotation to the method and the transaction interceptor will handle it.</p>
</div>
<div class="paragraph">
<p>In addition to this you can also create your own test stereotypes. For example we could create a <code>@TransactionalQuarkusTest</code>
as follows:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@QuarkusTest
@Stereotype
@Transactional
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface TransactionalQuarkusTest {
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>If we then apply this annotation to a test class it will act as if we had applied both the <code>@QuarkusTest</code> and
<code>@Transactional</code> annotations, e.g.:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@TransactionalQuarkusTest
public class TestStereotypeTestCase {

    @Inject
    UserTransaction userTransaction;

    @Test
    public void testUserTransaction() throws Exception {
        Assertions.assertEquals(Status.STATUS_ACTIVE, userTransaction.getStatus());
    }

}</code></pre>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="enrichment-via-quarkustestcallback"><a class="anchor" href="#enrichment-via-quarkustestcallback"></a>8. Enrichment via QuarkusTest*Callback</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Alternatively or additionally to an interceptor, you can enrich <strong>all</strong> your <code>@QuarkusTest</code> classes by implementing the following callback interfaces:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>io.quarkus.test.junit.callback.QuarkusTestBeforeAllCallback</code></p>
</li>
<li>
<p><code>io.quarkus.test.junit.callback.QuarkusTestBeforeEachCallback</code></p>
</li>
<li>
<p><code>io.quarkus.test.junit.callback.QuarkusTestAfterEachCallback</code></p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Such a callback implementation has to be registered as a "service provider" as defined by <code>java.util.ServiceLoader</code>.</p>
</div>
<div class="paragraph">
<p>E.g. the following sample callback:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">package org.acme.getting.started.testing;

import io.quarkus.test.junit.callback.QuarkusTestBeforeEachCallback;
import io.quarkus.test.junit.callback.QuarkusTestMethodContext;

public class MyQuarkusTestBeforeEachCallback implements QuarkusTestBeforeEachCallback {

    @Override
    public void beforeEach(QuarkusTestMethodContext context) {
        System.out.println("Executing " + context.getTestMethod());
    }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>has to be registered via <code>src/main/resources/META-INF/services/io.quarkus.test.junit.callback.QuarkusTestBeforeEachCallback</code> as follows:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">org.acme.getting.started.testing.MyQuarkusTestBeforeEachCallback</code></pre>
</div>
</div>
<div class="admonitionblock tip">
<table>
<tr>
<td class="icon">
<i class="fa icon-tip" title="Tip"></i>
</td>
<td class="content">
It is possible to read annotations from the test class or method to control what the callback shall be doing.
</td>
</tr>
</table>
</div>
<div class="admonitionblock warning">
<table>
<tr>
<td class="icon">
<i class="fa icon-warning" title="Warning"></i>
</td>
<td class="content">
While it is possible to use JUnit Jupiter callback interfaces like <code>BeforeEachCallback</code>, you might run into classloading issues because Quarkus has
         to run tests in a custom classloader which JUnit is not aware of.
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="sect1">
<h2 id="testing_different_profiles"><a class="anchor" href="#testing_different_profiles"></a>9. Testing Different Profiles</h2>
<div class="sectionbody">
<div class="paragraph">
<p>So far in all our examples we only start Quarkus once for all tests. Before the first test is run Quarkus will boot,
then all tests will run, then Quarkus will shutdown at the end. This makes for a very fast testing experience however
it is a bit limited as you can&#8217;t test different configurations.</p>
</div>
<div class="paragraph">
<p>To get around this Quarkus supports the idea of a test profile. If a test has a different profile to the previously
run test then Quarkus will be shut down and started with the new profile before running the tests. This is obviously
a bit slower, as it adds a shutdown/startup cycle to the test time, but gives a great deal of flexibility.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
In order to reduce the amount of times Quarkus needs to restart it is recommended that you place all tests
that need a specific profile into their own package, and then run tests alphabetically.
</td>
</tr>
</table>
</div>
<div class="sect2">
<h3 id="writing-a-profile"><a class="anchor" href="#writing-a-profile"></a>9.1. Writing a Profile</h3>
<div class="paragraph">
<p>To implement a test profile we need to implement <code>io.quarkus.test.junit.QuarkusTestProfile</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">package org.acme.getting.started.testing;

import java.util.Collections;
import java.util.Map;
import java.util.Set;

import io.quarkus.test.junit.QuarkusTestProfile;

public class MockGreetingProfile implements QuarkusTestProfile {

    @Override
    public Map&lt;String, String&gt; getConfigOverrides() { <i class="conum" data-value="1"></i><b>(1)</b>
        return Collections.singletonMap("quarkus.resteasy.path","/api");
    }

    @Override
    public Set&lt;Class&lt;?&gt;&gt; getEnabledAlternatives() { <i class="conum" data-value="2"></i><b>(2)</b>
        return Collections.singleton(MockGreetingService.class);
    }


    @Override
    public String getConfigProfile() { <i class="conum" data-value="3"></i><b>(3)</b>
        return "test";
    }
}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>This method allows us to override configuration properties. Here we are changing the JAX-RS root path.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>This method allows us to enable CDI <code>@Alternative</code> beans. This makes it easy to mock out certain beans functionality.</td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td>This can be used to change the config profile. As this default is <code>test</code> this does nothing, but is included for completeness.</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>Now we have defined our profile we need to include it on our test class. We do this with <code>@TestProfile(MockGreetingProfile.class)</code>.</p>
</div>
<div class="paragraph">
<p>All the test profile config is stored in a single class, which makes it easy to tell if the previous test ran with the
same configuration.</p>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="mock-support"><a class="anchor" href="#mock-support"></a>10. Mock Support</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Quarkus supports the use of mock objects using two different approaches. You can either use CDI alternatives to
mock out a bean for all test classes, or use <code>QuarkusMock</code> to mock out beans on a per test basis.</p>
</div>
<div class="sect2">
<h3 id="cdi-alternative-mechanism"><a class="anchor" href="#cdi-alternative-mechanism"></a>10.1. CDI <code>@Alternative</code> mechanism.</h3>
<div class="paragraph">
<p>To use this simply override the bean you wish to mock with a class in the <code>src/test/java</code> directory, and put the <code>@Alternative</code> and <code>@Priority(1)</code> annotations on the bean.
Alternatively, a convenient <code>io.quarkus.test.Mock</code> stereotype annotation could be used.
This built-in stereotype declares <code>@Alternative</code>, <code>@Priority(1)</code> and <code>@Dependent</code>.
For example if I have the following service:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@ApplicationScoped
public class ExternalService {

    public String service() {
        return "external";
    }

}</code></pre>
</div>
</div>
<div class="paragraph">
<p>I could mock it with the following class in <code>src/test/java</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@Mock
@ApplicationScoped <i class="conum" data-value="1"></i><b>(1)</b>
public class MockExternalService extends ExternalService {

    @Override
    public String service() {
        return "mock";
    }
}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>Overrides the <code>@Dependent</code> scope declared on the <code>@Mock</code> stereotype.</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>It is important that the alternative be present in the <code>src/test/java</code> directory rather than <code>src/main/java</code>, as otherwise
it will take effect all the time, not just when testing.</p>
</div>
<div class="paragraph">
<p>Note that at present this approach does not work with native image testing, as this would required the test alternatives
to be baked into the native image.</p>
</div>
</div>
<div class="sect2">
<h3 id="mocking-using-quarkusmock"><a class="anchor" href="#mocking-using-quarkusmock"></a>10.2. Mocking using QuarkusMock</h3>
<div class="paragraph">
<p>The <code>io.quarkus.test.junit.QuarkusMock</code> class can be used to temporarily mock out any normal scoped
bean. If you use this method in a <code>@BeforeAll</code> method the mock will take effect for all tests on the current class,
while if you use this in a test method the mock will only take effect for the duration of the current test.</p>
</div>
<div class="paragraph">
<p>This method can be used for any normal scoped CDI bean (e.g. <code>@ApplicationScoped</code>, <code>@RequestScoped</code> etc, basically
every scope except <code>@Singleton</code> and <code>@Dependent</code>).</p>
</div>
<div class="paragraph">
<p>An example usage could look like:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@QuarkusTest
public class MockTestCase {

    @Inject
    MockableBean1 mockableBean1;

    @Inject
    MockableBean2 mockableBean2;

    @BeforeAll
    public static void setup() {
        MockableBean1 mock = Mockito.mock(MockableBean1.class);
        Mockito.when(mock.greet("Stuart")).thenReturn("A mock for Stuart");
        QuarkusMock.installMockForType(mock, MockableBean1.class);  <i class="conum" data-value="1"></i><b>(1)</b>
    }

    @Test
    public void testBeforeAll() {
        Assertions.assertEquals("A mock for Stuart", mockableBean1.greet("Stuart"));
        Assertions.assertEquals("Hello Stuart", mockableBean2.greet("Stuart"));
    }

    @Test
    public void testPerTestMock() {
        QuarkusMock.installMockForInstance(new BonourGreeter(), mockableBean2); <i class="conum" data-value="2"></i><b>(2)</b>
        Assertions.assertEquals("A mock for Stuart", mockableBean1.greet("Stuart"));
        Assertions.assertEquals("Bonjour Stuart", mockableBean2.greet("Stuart"));
    }

    @ApplicationScoped
    public static class MockableBean1 {

        public String greet(String name) {
            return "Hello " + name;
        }
    }

    @ApplicationScoped
    public static class MockableBean2 {

        public String greet(String name) {
            return "Hello " + name;
        }
    }

    public static class BonourGreeter extends MockableBean2 {
        @Override
        public String greet(String name) {
            return "Bonjour " + name;
        }
    }
}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>As the injected instance is not available here we use <code>installMockForType</code>, this mock is used for both test methods</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>We use <code>installMockForInstance</code> to replace the injected bean, this takes effect for the duration of the test method.</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>Note that there is no dependency on Mockito, you can use any mocking library you like, or even manually override the
objects to provide the behaviour you require.</p>
</div>
<div class="sect3">
<h4 id="further-simplification-with-injectmock"><a class="anchor" href="#further-simplification-with-injectmock"></a>10.2.1. Further simplification with <code>@InjectMock</code></h4>
<div class="paragraph">
<p>Building on the features provided by <code>QuarkusMock</code>, Quarkus also allows users to effortlessly take advantage of <a href="https://site.mockito.org/">Mockito</a> for mocking the beans supported by <code>QuarkusMock</code>.
This functionality is available via the <code>@io.quarkus.test.junit.mockito.InjectMock</code> annotation which is available in the <code>quarkus-junit5-mockito</code> dependency.</p>
</div>
<div class="paragraph">
<p>Using <code>@InjectMock</code>, the previous example could be written as follows:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@QuarkusTest
public class MockTestCase {

    @InjectMock
    MockableBean1 mockableBean1; <i class="conum" data-value="1"></i><b>(1)</b>

    @InjectMock
    MockableBean2 mockableBean2;

    @BeforeEach
    public void setup() {
        Mockito.when(mockableBean1.greet("Stuart")).thenReturn("A mock for Stuart"); <i class="conum" data-value="2"></i><b>(2)</b>
    }

    @Test
    public void firstTest() {
        Assertions.assertEquals("A mock for Stuart", mockableBean1.greet("Stuart"));
        Assertions.assertEquals(null, mockableBean2.greet("Stuart")); <i class="conum" data-value="3"></i><b>(3)</b>
    }

    @Test
    public void secondTest() {
        Mockito.when(mockableBean2.greet("Stuart")).thenReturn("Bonjour Stuart"); <i class="conum" data-value="4"></i><b>(4)</b>
        Assertions.assertEquals("A mock for Stuart", mockableBean1.greet("Stuart"));
        Assertions.assertEquals("Bonjour Stuart", mockableBean2.greet("Stuart"));
    }

    @ApplicationScoped
    public static class MockableBean1 {

        public String greet(String name) {
            return "Hello " + name;
        }
    }

    @ApplicationScoped
    public static class MockableBean2 {

        public String greet(String name) {
            return "Hello " + name;
        }
    }
}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td><code>@InjectMock</code> results in a mock being and is available in test methods of the test class (other test classes are <strong>not</strong> affected by this)</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>The <code>mockableBean1</code> is configured here for every test method of the class</td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td>Since the <code>mockableBean2</code> mock has not been configured, it will return the default Mockito response.</td>
</tr>
<tr>
<td><i class="conum" data-value="4"></i><b>4</b></td>
<td>In this test the <code>mockableBean2</code> is configured, so it returns the configured response.</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>Although the test above is good for showing the capabilities of <code>@InjectMock</code>, it is not a good representation of a real test. In a real test
we would most likely configure a mock, but then test a bean that uses the mocked bean.
Here is an example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@QuarkusTest
public class MockGreetingServiceTest {

    @InjectMock
    GreetingService greetingService;

    @Test
    public void testGreeting() {
        when(greetingService.greet()).thenReturn("hi");
        given()
                .when().get("/greeting")
                .then()
                .statusCode(200)
                .body(is("hi")); <i class="conum" data-value="1"></i><b>(1)</b>
    }

    @Path("greeting")
    public static class GreetingResource {

        final GreetingService greetingService;

        public GreetingResource(GreetingService greetingService) {
            this.greetingService = greetingService;
        }

        @GET
        @Produces("text/plain")
        public String greet() {
            return greetingService.greet();
        }
    }

    @ApplicationScoped
    public static class GreetingService {
        public String greet(){
            return "hello";
        }
    }
}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>Since we configured <code>greetingService</code> as a mock, the <code>GreetingResource</code> which uses the <code>GreetingService</code> bean, we get the mocked response instead of the response of the regular <code>GreetingService</code> bean</td>
</tr>
</table>
</div>
</div>
<div class="sect3">
<h4 id="using-spies-instead-of-mocks-with-injectspy"><a class="anchor" href="#using-spies-instead-of-mocks-with-injectspy"></a>10.2.2. Using Spies instead of Mocks with <code>@InjectSpy</code></h4>
<div class="paragraph">
<p>Building on the features provided by <code>InjectMock</code>, Quarkus also allows users to effortlessly take advantage of <a href="https://site.mockito.org/">Mockito</a> for spying on the beans supported by <code>QuarkusMock</code>.
This functionality is available via the <code>@io.quarkus.test.junit.mockito.InjectSpy</code> annotation which is available in the <code>quarkus-junit5-mockito</code> dependency.</p>
</div>
<div class="paragraph">
<p>Sometimes when testing you only need to verify that a certain logical path was taken, or you only need to stub out a single method&#8217;s response while still executing the rest of the methods on the Spied clone. Please see <a href="https://javadoc.io/doc/org.mockito/mockito-core/latest/org/mockito/Mockito.html#spy-T-">Mockito documentation</a> for more details on Spy partial mocks.
In either of those situations a Spy of the object is preferable.
Using <code>@InjectSpy</code>, the previous example could be written as follows:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@QuarkusTest
public class SpyGreetingServiceTest {

    @InjectSpy
    GreetingService greetingService;

    @Test
    public void testDefaultGreeting() {
        given()
                .when().get("/greeting")
                .then()
                .statusCode(200)
                .body(is("hello"));

        Mockito.verify(greetingService, Mockito.times(1)).greet(); <i class="conum" data-value="1"></i><b>(1)</b>
    }

    @Test
    public void testOverrideGreeting() {
        when(greetingService.greet()).thenReturn("hi"); <i class="conum" data-value="2"></i><b>(2)</b>
        given()
                .when().get("/greeting")
                .then()
                .statusCode(200)
                .body(is("hi")); <i class="conum" data-value="3"></i><b>(3)</b>
    }

    @Path("greeting")
    public static class GreetingResource {

        final GreetingService greetingService;

        public GreetingResource(GreetingService greetingService) {
            this.greetingService = greetingService;
        }

        @GET
        @Produces("text/plain")
        public String greet() {
            return greetingService.greet();
        }
    }

    @ApplicationScoped
    public static class GreetingService {
        public String greet(){
            return "hello";
        }
    }
}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>Instead of overriding the value, we just want to ensure that the greet method on our <code>GreetingService</code> was called by this test.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>Here we are telling the Spy to return "hi" instead of "hello". When the <code>GreetingResource</code> requests the greeting from <code>GreetingService</code> we get the mocked response instead of the response of the regular <code>GreetingService</code> bean</td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td>We are verifying that we get the mocked response from the Spy.</td>
</tr>
</table>
</div>
</div>
<div class="sect3">
<h4 id="using-injectmock-with-restclient"><a class="anchor" href="#using-injectmock-with-restclient"></a>10.2.3. Using <code>@InjectMock</code> with <code>@RestClient</code></h4>
<div class="paragraph">
<p>The <code>@RegisterRestClient</code> registers the implementation of the rest-client at runtime, and because the bean needs to be a regular scope, you have to annotate your interface with <code>@ApplicationScoped</code>.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@Path("/")
@ApplicationScoped
@RegisterRestClient
public interface GreetingService {

    @GET
    @Path("/hello")
    @Produces(MediaType.TEXT_PLAIN)
    String hello();
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>For the test class here is an example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@QuarkusTest
public class GreetingResourceTest {

    @InjectMock
    @RestClient <i class="conum" data-value="1"></i><b>(1)</b>
    GreetingService greetingService;

    @Test
    public void testHelloEndpoint() {
        Mockito.when(greetingService.hello()).thenReturn("hello from mockito");

        given()
          .when().get("/hello")
          .then()
             .statusCode(200)
             .body(is("hello from mockito"));
    }

}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>Indicate that this injection point is meant to use an instance of <code>RestClient</code>.</td>
</tr>
</table>
</div>
</div>
</div>
<div class="sect2">
<h3 id="mocking-with-panache"><a class="anchor" href="#mocking-with-panache"></a>10.3. Mocking with Panache</h3>
<div class="paragraph">
<p>If you are using the <code>quarkus-hibernate-orm-panache</code> or <code>quarkus-mongodb-panache</code> extensions, check out the <a href="hibernate-orm-panache#mocking">Hibernate ORM with Panache Mocking</a> and <a href="mongodb-panache#mocking">MongoDB with Panache Mocking</a> documentation for the easiest way to mock your data access.</p>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="testing-security"><a class="anchor" href="#testing-security"></a>11. Testing Security</h2>
<div class="sectionbody">
<div class="paragraph">
<p>If you are using Quarkus Security, check out the <a href="security.adoc#testing-security">Testing Security</a> section for information on how to easily test security features of the application.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="quarkus-test-resource"><a class="anchor" href="#quarkus-test-resource"></a>12. Starting services before the Quarkus application starts</h2>
<div class="sectionbody">
<div class="paragraph">
<p>A very common need is to start some services on which your Quarkus application depends, before the Quarkus application starts for testing. To address this need, Quarkus provides <code>@io.quarkus.test.common.QuarkusTestResource</code> and <code>io.quarkus.test.common.QuarkusTestResourceLifecycleManager</code>.</p>
</div>
<div class="paragraph">
<p>By simply annotating any test in the test suite with <code>@QuarkusTestResource</code>, Quarkus will run the corresponding <code>QuarkusTestResourceLifecycleManager</code> before any tests are run.
A test suite is also free to utilize multiple <code>@QuarkusTestResource</code> annotations, in which case all the corresponding <code>QuarkusTestResourceLifecycleManager</code> objects will be run before the tests.</p>
</div>
<div class="paragraph">
<p>Quarkus provides a few implementations of <code>QuarkusTestResourceLifecycleManager</code> out of the box (see <code>io.quarkus.test.h2.H2DatabaseTestResource</code> which starts an H2 database, or <code>io.quarkus.test.kubernetes.client.KubernetesMockServerTestResource</code> which starts a mock Kubernetes API server),
but it is common to create custom implementations to address specific application needs.
Common cases include starting docker containers using <a href="https://www.testcontainers.org/">Testcontainers</a> (an example of which can be found <a href="https://github.com/quarkusio/quarkus-quickstarts/blob/master/kafka-quickstart/src/test/java/org/acme/kafka/KafkaResource.java">here</a>),
or starting a mock HTTP server using <a href="http://wiremock.org/">Wiremock</a> (an example of which can be found <a href="https://github.com/geoand/quarkus-test-demo/blob/master/src/test/java/org/acme/getting/started/country/WiremockCountries.java">here</a>).</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="native-executable-testing"><a class="anchor" href="#native-executable-testing"></a>13. Native Executable Testing</h2>
<div class="sectionbody">
<div class="paragraph">
<p>It is also possible to test native executables using <code>@NativeImageTest</code>. This supports all the features mentioned in this
guide except injecting into tests (and the native executable runs in a separate non-JVM process this is not really possible).</p>
</div>
<div class="paragraph">
<p>This is covered in the <a href="building-native-image">Native Executable Guide</a>.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="test-from-ide"><a class="anchor" href="#test-from-ide"></a>14. Running <code>@QuarkusTest</code> from an IDE</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Most IDEs offer the possibility to run a selected class as JUnit test directly. For this you should set a few properties in the settings of your chosen IDE:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>java.util.logging.manager</code> (see <a href="logging">Logging Guide</a>)</p>
</li>
<li>
<p><code>maven.home</code> (only if there are any custom settings in <code>${maven.home}/conf/settings.mxl</code>, see <a href="maven-tooling">Maven Guide</a>)</p>
</li>
<li>
<p><code>maven.settings</code> (in case a custom version of <code>settings.xml</code> file should be used for the tests)</p>
</li>
</ul>
</div>
<div class="sect2">
<h3 id="eclipse-separate-jre-definition"><a class="anchor" href="#eclipse-separate-jre-definition"></a>14.1. Eclipse separate JRE definition</h3>
<div class="paragraph">
<p>Copy your current "Installed JRE" definition into a new one, where you will add the properties as a new VM arguments:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>-Djava.util.logging.manager=org.jboss.logmanager.LogManager</code></p>
</li>
<li>
<p><code>-Dmaven.home=&lt;path-to-your-maven-installation&gt;</code></p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Use this JRE definition as your Quarkus project targeted runtime and the workaround will be applied to any "Run as JUnit" configuration.</p>
</div>
</div>
<div class="sect2">
<h3 id="vscode-run-with-configuration"><a class="anchor" href="#vscode-run-with-configuration"></a>14.2. VSCode "run with" configuration</h3>
<div class="paragraph">
<p>The <code>settings.json</code> placed in the root of your project directory or in the workspace will need the workaround in your test configuration:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="json" class="language-json hljs">"java.test.config": [
    {
        "name": "quarkusConfiguration",
        "vmargs": [ "-Djava.util.logging.manager=org.jboss.logmanager.LogManager -Dmaven.home=&lt;path-to-your-maven-installation&gt; ..." ],
        ...
    },
  ...
]</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="intellij-junit-template"><a class="anchor" href="#intellij-junit-template"></a>14.3. IntelliJ JUnit template</h3>
<div class="paragraph">
<p>Nothing needed in IntelliJ because the IDE will pick the <code>systemPropertyVariables</code> from the surefire plugin configuration in <code>pom.xml</code>.</p>
</div>
</div>
</div>
</div>
    </div>
  </div>
</div>

  </div>

  <div class="content project-footer">
  <div class="footer-section">
    <div class="logo-wrapper">
      <a href="/"><img src="/assets/images/quarkus_logo_horizontal_rgb_reverse.svg" class="project-logo" title="Quarkus"></a>
    </div>
  </div>
  <div class="grid-wrapper">
    <p class="grid__item width-3-12">Quarkus is open. All dependencies of this project are available under the <a href='https://www.apache.org/licenses/LICENSE-2.0' target='_blank'>Apache Software License 2.0</a> or compatible license.<br /><br />This website was built with <a href='https://jekyllrb.com/' target='_blank'>Jekyll</a>, is hosted on <a href='https://pages.github.com/' target='_blank'>Github Pages</a> and is completely open source. If you want to make it better, <a href='https://github.com/quarkusio/quarkusio.github.io' target='_blank'>fork the website</a> and show us what you’ve got.</p>

    
      <div class="width-1-12 project-links">
        <span>Navigation</span>
        <ul class="footer-links width-1-12">
          
            <li><a href="/">Home</a></li>
          
            <li><a href="/guides">Guides</a></li>
          
            <li><a href="/community/#contributing">Contribute</a></li>
          
            <li><a href="/faq">FAQ</a></li>
          
            <li><a href="/get-started">Get Started</a></li>
          
        </ul>
      </div>
    
      <div class="width-1-12 project-links">
        <span>Contribute</span>
        <ul class="footer-links width-1-12">
          
            <li><a href="https://twitter.com/quarkusio">Follow us</a></li>
          
            <li><a href="https://github.com/quarkusio">GitHub</a></li>
          
            <li><a href="/security">Security&nbsp;policy</a></li>
          
        </ul>
      </div>
    
      <div class="width-1-12 project-links">
        <span>Get Help</span>
        <ul class="footer-links width-1-12">
          
            <li><a href="https://groups.google.com/forum/#!forum/quarkus-dev">Forums</a></li>
          
            <li><a href="https://quarkusio.zulipchat.com">Chatroom</a></li>
          
        </ul>
      </div>
    

    
      <div class="width-3-12 more-links">
        <span>Quarkus is made of community projects</span>
        <ul class="footer-links">
          
            <li><a href="https://vertx.io/" target="_blank">Eclipse Vert.x</a></li>
          
            <li><a href="https://microprofile.io" target="_blank">Eclipse MicroProfile</a></li>
          
            <li><a href="https://hibernate.org" target="_blank">Hibernate</a></li>
          
            <li><a href="https://netty.io" target="_blank">Netty</a></li>
          
            <li><a href="https://resteasy.github.io" target="_blank">RESTEasy</a></li>
          
            <li><a href="https://camel.apache.org" target="_blank">Apache Camel</a></li>
          
            <li><a href="https://code.quarkus.io/" target="_blank">And many more...</a></li>
          
        </ul>
      </div>
    
  </div>
</div>
  <div class="content redhat-footer">
  <div class="grid-wrapper">
    <span class="licence">
      <i class="fab fa-creative-commons"></i><i class="fab fa-creative-commons-by"></i> <a href="https://creativecommons.org/licenses/by/3.0/" target="_blank">CC by 3.0</a> | <a href="https://www.redhat.com/en/about/privacy-policy">Privacy Policy</a>
    </span>
    <span class="redhat">
      Sponsored by
    </span>
    <span class="redhat-logo">
      <a href="https://www.redhat.com/" target="_blank"><img src="/assets/images/redhat_reversed.svg"></a>
    </span>
  </div>
</div>


  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js" integrity="sha384-8gBf6Y4YYq7Jx97PIqmTwLPin4hxIzQw5aDmUg/DDhul9fFpbbLcLh3nTIIDJKhx" crossorigin="anonymous"></script>
  <script type="text/javascript" src="/assets/javascript/mobile-nav.js"></script>
  <script type="text/javascript" src="/assets/javascript/scroll-down.js"></script>
  <script src="/assets/javascript/satellite.js" type="text/javascript"></script>
  <script src="https://quarkus.io/guides/javascript/config.js" type="text/javascript"></script>
  <script src="/assets/javascript/search-filter.js" type="text/javascript"></script>
  <script src="/assets/javascript/back-to-top.js" type="text/javascript"></script>
</body>

</html>
